package edu.gxnu.cetcdemo.controller;

import edu.gxnu.cetcdemo.pojo.User;
import edu.gxnu.cetcdemo.service.UserService;
import edu.gxnu.cetcdemo.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("用户登录接口")
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        System.out.println("receive login request");
        return userService.login(user);
    }

    @ApiOperation("用户注册接口")
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        return userService.register(user);
    }

    @ApiOperation("浏览个人信息接口")
    @GetMapping("/profile/{userId}")
    public Result queryProfile(@PathVariable long userId){
        return  userService.queryProfile(userId);
    }

    @ApiOperation("修改个人信息接口")
    @PutMapping("/profile")
    public Result updateProfile(@RequestBody User user){
        return  userService.updateProfile(user);
    }
}
